<template>
	<view class="index-con">
		<view>
			<view class="search-con" :style="{ paddingTop: systemHeight + 'px' }">
				<image class="ai-icon" mode="scaleToFill" :src="aiSrc" @click="toAI"></image>
				<u-input placeholder="请输入施工计划" class="input-con" v-model="keyword" />
				<image class="search-icon" mode="scaleToFill" :src="searchSrc" @click="toSearch"></image>
			</view>
			<view class="box"></view>
			<view>
				<view>
					<view class="menu-title">设备详情</view>
					<view class="menu-con1" @click="switchTo('/pages/device/index')">
						<u-row justify="space-between" gutter="10">
							<u-col span="4">
								<view class="menu1-item">
									<view class="name">安全帽</view>
									<image class="wh90" :src="aqmSrc" />
								</view>
							</u-col>
							<u-col span="4">
								<view class="menu1-item">
									<view class="name">摄像头</view>
									<image class="wh100" :src="sxtSrc" />
								</view>
							</u-col>
							<u-col span="4">
								<view class="menu1-item">
									<view class="name">记录仪</view>
									<image class="wh100" :src="jlySrc" />
								</view>
							</u-col>
						</u-row>
					</view>
				</view>
				<view>
					<view class="menu-title">施工反馈</view>
					<view class="menu-con2">
						<u-row justify="space-between" gutter="10">
							<u-col span="4">
								<view class="menu2-item" @click="open">
									<image class="wh80" :src="yhtbSrc" />
									<view class="name">隐患填报</view>
								</view>
							</u-col>
							<u-col span="4">
								<view class="menu2-item" @click="open2">
									<image class="wh80" :src="lsjhSrc" />
									<view class="name">临时计划</view>
								</view>
							</u-col>
							<u-col span="4">
								<view class="menu2-item" @click="open3">
									<image class="wh80" :src="wyssSrc" />
									<view class="name">我要申诉</view>
								</view>
							</u-col>
						</u-row>
					</view>
				</view>
				<view>
					<view class="menu-title">云监管理</view>
					<view class="menu-con3" style="background: white; padding-bottom: 20px">
						<u-row justify="space-between" gutter="10">
							<u-col span="4">
								<view class="bgcon bg1" @click="toNextPage('/pages/task/remote/remote?which=正在施工')">
									<view class="counts">{{ onlineNum }}</view>
									<view class="menu-label">正在施工</view>
								</view>
							</u-col>
							<u-col span="4">
								<view class="bgcon bg2">
									<view class="counts">{{ completedNum }}</view>
									<view class="menu-label">今日完工</view>
								</view>
							</u-col>
							<u-col span="4">
								<view class="bgcon bg3">
									<view class="counts">{{ monthCompletedNum }}</view>
									<view class="menu-label">当月施工</view>
								</view>
							</u-col>
						</u-row>
						<u-row justify="space-between" gutter="10">
							<u-col span="4">
								<view class="bgcon bg4" @click="toNextPage('/pages/task/monitor/monitor?which=正在监理')">
									<view class="counts">{{ xjyOnlineNum }}</view>
									<view class="menu-label">正在监理</view>
								</view>
							</u-col>
							<u-col span="4">
								<view class="bgcon bg5">
									<view class="counts">{{ xjyCompletedNum }}</view>
									<view class="menu-label">今日监理</view>
								</view>
							</u-col>
							<u-col span="4">
								<view class="bgcon bg6">
									<view class="counts">{{ monthCompletedNum ? 0 : '' }}</view>
									<view class="menu-label">督监图片</view>
								</view>
							</u-col>
						</u-row>
					</view>
				</view>
			</view>
		</view>
		<uni-popup ref="popup" :is-mask-click="false" type="center" background-color="#fff" border-radius="18rpx 18rpx 18rpx 18rpx">
			<view class="dialogBox">
				<view class="topBox">
					<view class="topLeft">隐患填报</view>
					<view class="closeBtn" @click="closeDialog">关闭</view>
				</view>
				<view class="formBox">
					<uni-data-select class="inputItem" v-model="value" :localdata="range" placeholder="请选择施工计划"></uni-data-select>
					<uni-data-select class="inputItem" v-model="value" :localdata="range" placeholder="请选择隐患类型"></uni-data-select>
					<uni-easyinput class="inputItem" type="textarea" v-model="value" placeholder="请输入隐患说明"></uni-easyinput>
					<view class="latlng" style="color: #555; margin-bottom: 20rpx">当前位置经纬度：{{ lng + ', ' + lat }}</view>
					<view class="uploadImg" style="color: #555; margin-bottom: 20rpx">上传图片：</view>
					<u-upload :fileList="fileList" @afterRead="afterRead" @delete="deletePic" name="1" multiple :maxCount="10"></u-upload>
				</view>
				<view class="botBtns">
					<u-button class="btnStyle" type="primary" @click="closeDialog">确认</u-button>
					<u-button class="btnStyle" @click="closeDialog">取消</u-button>
				</view>
			</view>
		</uni-popup>
		<uni-popup ref="popup2" :is-mask-click="false" type="center" background-color="#fff" border-radius="18rpx 18rpx 18rpx 18rpx">
			<view class="dialogBox2">
				<view class="topBox">
					<view class="topLeft">临时施工计划申报</view>
					<view class="closeBtn" @click="closeDialog">关闭</view>
				</view>
				<view class="formBox">
					<form @submit="formSubmit" @reset="formReset">
						<view class="uni-form-item uni-column">
							<view class="title">名称：</view>
							<input class="uni-input" name="input" placeholder="请输入施工计划名称" />
						</view>
						<view class="uni-form-item uni-column">
							<view class="title">内容：</view>
							<input class="uni-input" name="input" placeholder="请输入施工计划内容" />
						</view>
						<view class="uni-form-item uni-column">
							<view class="title">地区：</view>
							<input class="uni-input" name="input" placeholder="请输入地市区县名称" />
						</view>
						<view class="uni-form-item uni-column" @click="selTime(0)">
							<view class="title">开始时间：</view>
							<view class="timeBtn">{{ startTime ? startTime : '请选择施工计划开始时间' }}</view>
							<u-datetime-picker @confirm="confirmTime1" @cancel="cancel1" :show="timeShow1" v-model="startTime" mode="date"></u-datetime-picker>
						</view>
						<view class="uni-form-item uni-column" @click="selTime(1)">
							<view class="title">结束时间：</view>
							<view class="timeBtn">{{ endTime ? endTime : '请选择施工计划结束时间' }}</view>
							<u-datetime-picker @confirm="confirmTime2" @cancel="cancel2" :show="timeShow2" v-model="endTime" mode="date"></u-datetime-picker>
						</view>

						<view class="uni-form-item uni-column">
							<view class="title">是否需要计量签证：</view>
							<radio-group name="radio">
								<label>
									<radio value="radio1" />
									<text>是</text>
								</label>
								<label style="margin-left: 40rpx">
									<radio value="radio2" />
									<text>否</text>
								</label>
							</radio-group>
						</view>
						<view class="uni-form-item uni-column">
							<view class="title">是否有重大危险源：</view>
							<radio-group name="radio">
								<label>
									<radio value="radio1" />
									<text>是</text>
								</label>
								<label style="margin-left: 40rpx">
									<radio value="radio2" />
									<text>否</text>
								</label>
							</radio-group>
						</view>
						<view class="uni-form-item uni-column">
							<view class="title">是否高危场景作业：</view>
							<radio-group name="radio">
								<label>
									<radio value="radio1" />
									<text>是</text>
								</label>
								<label style="margin-left: 40rpx">
									<radio value="radio2" />
									<text>否</text>
								</label>
							</radio-group>
						</view>
						<view class="uni-form-item uni-column">
							<view class="title">是否为隐蔽性工程：</view>
							<radio-group name="radio">
								<label>
									<radio value="radio1" />
									<text>是</text>
								</label>
								<label style="margin-left: 40rpx">
									<radio value="radio2" />
									<text>否</text>
								</label>
							</radio-group>
						</view>
						<view class="botBtns">
							<u-button class="btnStyle" type="primary" form-type="submit">确认</u-button>
							<u-button class="btnStyle" form-type="reset">取消</u-button>
						</view>
					</form>
				</view>
			</view>
		</uni-popup>
		<uni-popup ref="popup3" :is-mask-click="false" type="center" background-color="#fff" border-radius="18rpx 18rpx 18rpx 18rpx">
			<view class="dialogBox3">
				<view class="topBox">
					<view class="topLeft">我要申诉</view>
					<view class="closeBtn" @click="closeDialog">关闭</view>
				</view>
				<view class="formBox">
					<uni-data-select class="inputItem" v-model="value3" :localdata="range3" placeholder="请选择施工计划"></uni-data-select>
					<uni-data-select class="inputItem" v-model="value3" :localdata="range3" placeholder="请选择申诉类型"></uni-data-select>
					<uni-easyinput class="inputItem" type="textarea" v-model="value3" placeholder="请输入申诉说明"></uni-easyinput>
					<view class="latlng" style="color: #555; margin-bottom: 20rpx">当前位置经纬度：{{ lng + ', ' + lat }}</view>
				</view>
				<view class="botBtns">
					<u-button class="btnStyle" type="primary" @click="closeDialog">确认</u-button>
					<u-button class="btnStyle" @click="closeDialog">取消</u-button>
				</view>
			</view>
		</uni-popup>
	</view>
</template>

<script>
import { getOnlineNum, getCompletedNum, getXjyOnlineNum, getXjyCompletedNum } from '@/api/index';
import { testPost } from '@/api/test/index.js';
// import store from "../../store";
// import { mapGetters } from "vuex";
import aiSrc from '../../static/images/AI.png';
import searchSrc from '@/static/images/navi.png';
import aqmSrc from '@/static/images/aqm.png';
import sxtSrc from '@/static/images/sxt.png';
import jlySrc from '@/static/images/jly.png';
import yhtbSrc from '@/static/images/yhtb.png';
import lsjhSrc from '@/static/images/lsjh.png';
import wyssSrc from '@/static/images/wyss.png';
import { formatTime } from '@/utils/date.js';
export default {
	data() {
		return {
			aiSrc,
			searchSrc,
			aqmSrc,
			sxtSrc,
			jlySrc,
			yhtbSrc,
			lsjhSrc,
			wyssSrc,
			keyword: '', // 搜索关键字
			//顶部导航栏高度
			systemHeight: undefined,
			//经纬度
			lat: undefined,
			lng: undefined,
			//弹窗1数据
			value: undefined,
			range: [
				{ value: 0, text: '篮球' },
				{ value: 1, text: '足球' },
				{ value: 2, text: '游泳' }
			],
			//弹窗2数据
			value2: undefined,
			location: undefined,
			range2: [
				{ value: 0, text: '篮球' },
				{ value: 1, text: '足球' },
				{ value: 2, text: '游泳' }
			],
			timeShow1: false,
			timeShow2: false,
			startTime: '',
			endTime: '',
			//弹窗3数据
			value3: undefined,
			range3: [
				{ value: 0, text: '篮球' },
				{ value: 1, text: '足球' },
				{ value: 2, text: '游泳' }
			],
			//图片上传
			fileList: [],

			//云监管理部分数据
			onlineNum: undefined, //摄像头在线数量
			completedNum: undefined, //摄像头今日完工数量
			monthCompletedNum: undefined, //摄像头本月完工数量
			xjyOnlineNum: undefined, //正在监理or巡检仪在线数量
			xjyCompletedNum: undefined //今日监理数量
		};
	},
	onLoad(e) {
		const systemInfo = uni.getSystemInfoSync();
		const urlParams = new URLSearchParams(window.location.search);
		this.systemHeight = Number(urlParams.get('systemHeight')) || systemInfo.statusBarHeight;
		uni.setStorageSync('systemHeight', this.systemHeight);
	},
	onShow() {
		// console.log("username: ",this.userName);
		this.getData();
	},
	methods: {
		toAI() {
			console.log('TODO跳转ai页面');
		},
		toSearch() {
			console.log('搜索关键字：', this.keyword);
			console.log('TODO跳转搜索页面');
		},
		//请求数据
		getData() {
			//获取摄像头在线数量
			let obj = {
				phone: String(13337211791)
			};
			getOnlineNum(obj)
				.then((res) => {
					// console.log('res: ', res);
					this.onlineNum = res.data;
				})
				.catch((err) => {
					console.log('err: ', err);
				});

			//获取摄像头完工数量
			getCompletedNum(obj)
				.then((res) => {
					// console.log('res: ', res);
					this.completedNum = res.data.todayNum;
					this.monthCompletedNum = res.data.monthNum;
				})
				.catch((err) => {
					console.log('err: ', err);
				});

			//获取巡检仪在线数量
			getXjyOnlineNum(obj)
				.then((res) => {
					// console.log('res2: ', res);
					this.xjyOnlineNum = res.data;
				})
				.catch((err) => {
					console.log(err);
				});

			//获取今日监理数量
			getXjyCompletedNum(obj).then((res) => {
				// console.log(res);
				this.xjyCompletedNum = res.data;
			});

			//测试dcoos接口
			// let testObj = {
			// 	deviceid: 43010002031320012335,
			// 	status: 0
			// };
			// testPost(testObj).then((res) => {
			// 	console.log(456, res);
			// });
		},
		//打开弹窗1
		open() {
			return;
			this.$refs.popup.open();
			uni.getLocation({
				type: 'wgs84', // 国际标准坐标系wgs84\国测局gcj02
				accuracy: 'best',
				isHighAccuracy: true,
				success: (res) => {
					this.lng = res.longitude;
					this.lat = res.latitude;
					console.log('经度:', res.longitude, '纬度:', res.latitude);
				},
				fail: (err) => {
					if (err.errMsg.includes('auth deny')) {
						uni.showModal({ content: '定位权限被拒绝，请手动开启' });
					} else {
						console.log(err);
					}
				}
			});
		},
		//打开弹窗2
		open2() {
			return;
			this.$refs.popup2.open();
		},
		//地区选择
		onConfirm(e) {
			console.log(e);
		},
		//日期选择
		selTime(num) {
			if (num) {
				this.timeShow2 = true;
			} else {
				this.timeShow1 = true;
			}
		},

		//确定选择
		confirmTime1(e) {
			setTimeout(() => {
				this.startTime = formatTime(e.value, 'yyyy-MM-dd');
			});
			this.timeShow1 = false;
		},
		confirmTime2(e) {
			setTimeout(() => {
				this.endTime = formatTime(e.value, 'yyyy-MM-dd');
			});
			this.timeShow2 = false;
		},

		//取消选择
		cancel1() {
			this.startTime = undefined;
			this.timeShow1 = false;
		},
		cancel2() {
			this.endTime = undefined;
			this.timeShow2 = false;
		},

		//弹窗2表单
		formSubmit(e) {
			console.log('form发生了submit事件，携带数据为：' + JSON.stringify(e.detail.value));
			this.startTime = undefined;
			this.endTime = undefined;
			this.$refs.popup2.close();
		},
		formReset(e) {
			console.log('清空数据');
			this.startTime = undefined;
			this.endTime = undefined;
			this.$refs.popup2.close();
		},
		//打开弹窗3
		open3() {
			return;
			this.$refs.popup3.open();
			uni.getLocation({
				type: 'wgs84', // 国际标准坐标系wgs84\国测局gcj02
				accuracy: 'best',
				isHighAccuracy: true,
				success: (res) => {
					this.lng = res.longitude;
					this.lat = res.latitude;
					console.log('经度:', res.longitude, '纬度:', res.latitude);
				},
				fail: (err) => {
					if (err.errMsg.includes('auth deny')) {
						uni.showModal({ content: '定位权限被拒绝，请手动开启' });
					} else {
						console.log(err);
					}
				}
			});
		},
		//关闭弹窗
		closeDialog() {
			//弹窗1关闭
			this.$refs.popup.close();
			this.value = undefined;

			//弹窗2关闭
			this.$refs.popup2.close();
			this.startTime = undefined;
			this.endTime = undefined;

			//弹窗3关闭
			this.$refs.popup3.close();
			this.value3 = undefined;
		},

		//图片上传
		afterRead() {
			console.log(111);
		},
		deletePic() {
			console.log(222);
		},
		//普通页面跳转
		toNextPage(url) {
			return;
			uni.navigateTo({
				url
			});
		},
		// tab页面跳转
		switchTo(url) {
			uni.switchTab({
				url
			});
		}
	}
};
</script>

<style lang="scss">
@import '../../static/css/common.scss';

.uni-textarea-placeholder {
	color: #6a6a6a !important;
}
.uni-form-item {
	padding: 20rpx 0;
	display: flex;
	height: 45rpx;
	line-height: 45rpx;
	// background-color: skyblue;

	.uni-input {
		// background-color: pink;
		width: 100%;
		height: 45rpx;
		line-height: 45rpx;
		font-size: 28rpx;
		color: #6a6a6a;
	}
	.uni-input-placeholder {
		color: #6a6a6a;
	}

	.timeBtn {
		height: 100%;
		color: #6a6a6a;
	}

	.title {
		// width: 300rpx;
		// background-color: skyblue;
		white-space: nowrap;
		margin-right: 20rpx;
	}
}
.dialogBox {
	width: 660rpx;
	height: 925rpx;
	border-radius: 50rpx;
	background-color: #fff;
	box-sizing: border-box;
	padding: 40rpx;

	.topBox {
		width: 100%;
		height: 60rpx;
		border-bottom: 1rpx solid #eee;
		// background-color: pink;
		display: flex;
		justify-content: space-between;

		.topLeft {
			font-size: 30rpx;
			font-weight: bold;
		}

		.closeBtn {
			color: #aaa;
		}
	}

	.formBox {
		height: 630rpx;
		padding: 40rpx 0;
		padding-top: 30rpx;

		.inputItem {
			margin-bottom: 20rpx;
		}
	}

	.botBtns {
		height: 60rpx;
		padding-top: 30rpx;
		// border-top: 1rpx solid #eee;
		// background-color: skyblue;

		.btnStyle {
			border-radius: 14rpx;
			width: 130rpx;
			height: 60rpx;
			font-size: 28rpx;
			margin-left: 20rpx;
			float: right;
		}
	}
}

.dialogBox2 {
	width: 660rpx;
	height: 976rpx;
	border-radius: 40rpx;
	background-color: #fff;
	box-sizing: border-box;
	padding: 40rpx;

	.topBox {
		width: 100%;
		height: 60rpx;
		border-bottom: 1rpx solid #eee;
		display: flex;
		justify-content: space-between;

		.topLeft {
			font-size: 30rpx;
			font-weight: bold;
		}

		.closeBtn {
			color: #aaa;
		}
	}

	.uni-radio-input {
		width: 26rpx;
		height: 26rpx;
		margin-top: -6rpx;
	}

	::v-deep .uni-radio-input-checked {
		background-color: #444 !important;
		border-color: #444 !important;
	}

	.formBox {
		height: 740rpx;
		padding: 20rpx 0;

		.inputItem {
			margin-bottom: 20rpx;
		}
	}

	.botBtns {
		height: 60rpx;
		padding-top: 30rpx;
		// border-top: 1rpx solid #eee;

		.btnStyle {
			border-radius: 14rpx;
			width: 130rpx;
			height: 60rpx;
			font-size: 28rpx;
			margin-left: 20rpx;
			float: right;
		}
	}
}

.dialogBox3 {
	width: 660rpx;
	height: 700rpx;
	border-radius: 50rpx;
	background-color: #fff;
	box-sizing: border-box;
	padding: 40rpx;

	.topBox {
		width: 100%;
		height: 60rpx;
		border-bottom: 1rpx solid #eee;
		display: flex;
		justify-content: space-between;

		.topLeft {
			font-size: 30rpx;
			font-weight: bold;
		}

		.closeBtn {
			color: #aaa;
		}
	}

	.formBox {
		height: 400rpx;
		padding: 40rpx 0;
		padding-top: 30rpx;

		.inputItem {
			margin-bottom: 20rpx;
		}
	}

	.botBtns {
		height: 60rpx;
		padding-top: 40rpx;
		// border-top: 1rpx solid #eee;

		.btnStyle {
			border-radius: 14rpx;
			width: 130rpx;
			height: 60rpx;
			font-size: 28rpx;
			margin-left: 20rpx;
			float: right;
		}
	}
}

.index-con {
	font-size: 28rpx;
	background: #f4f4f4;
	// height: 100vh;
	.search-con {
		height: 120rpx;
		line-height: 120rpx;
		background: rgb(64, 93, 247);
		display: flex;
		justify-content: center;
		align-items: center;
		// padding-top: 40px;

		& .ai-icon {
			width: 60rpx;
			height: 60rpx;
			@extend .ml;
		}

		& .input-con {
			@extend .ml;
			@extend .mr;
			width: 200rpx;
			background: white;
			border-radius: 18rpx;
		}

		& .search-icon {
			width: 60rpx;
			height: 60rpx;
			@extend .mr;
		}
	}

	.menu-title {
		color: black;
		font-size: 32rpx;
		text-align: left;
		font-weight: bold;
		font-family: 黑体;
		line-height: 1.5;
		padding: 28rpx;
		padding-bottom: 15rpx;
		margin-top: 15rpx;
	}

	.menu-con1,
	.menu-con2,
	.menu-con3 {
		padding-left: 28rpx;
		padding-right: 28rpx;
	}

	.menu1-item {
		background: white;
		width: calc((100vw - 90rpx) / 3);
		height: 260rpx;
		& .name {
			font-weight: bold;
			color: rgba(0, 0, 0, 0.65);
			padding: 18rpx 26rpx;
			padding-bottom: 0;
		}
		& .wh100 {
			width: 100%;
			height: 200rpx;
		}
		& .wh90 {
			width: 86%;
			height: 190rpx;
			margin-top: 12rpx;
			margin-left: 10%;
		}

		border-radius: 20rpx;
		// background: pink !important;
	}

	.menu2-item {
		width: calc((100vw - 90rpx) / 3);
		height: 220rpx;
		display: flex;
		flex-direction: column;
		justify-content: center;
		align-items: center;
		background-color: #fff;
		border-radius: 20rpx;
		padding-bottom: 18rpx;

		& .name {
			text-align: center;
			font-weight: bold;
			color: rgba(0, 0, 0, 0.65);
		}
		& .wh80 {
			display: block;
			margin: 0;
			padding: 0;
			width: 160rpx;
			height: 160rpx;
		}
	}

	.bgcon {
		height: 180rpx;
		display: flex;
		flex-flow: column;
		justify-content: center;
		align-items: center;
		gap: 2px;
		background-color: rgb(243, 243, 255);
		border-radius: 10px;
		margin-top: 10px;
		font-size: 46rpx;
	}

	.bg1 {
		background-color: rgb(243, 243, 255);
		color: rgb(22, 34, 182);
	}

	.bg2 {
		background-color: rgb(254, 240, 231);
		color: rgb(210, 69, 13);
	}

	.bg3 {
		background-color: rgb(233, 255, 243);
		color: rgb(18, 135, 65);
	}

	.bg4 {
		background-color: rgb(255, 235, 242);
		color: rgb(219, 12, 18);
	}

	.bg5 {
		background-color: rgb(243, 243, 255);
		color: rgb(18, 30, 174);
	}

	.bg6 {
		background-color: rgb(254, 241, 232);
		color: rgb(212, 73, 16);
	}

	.menu-label {
		font-weight: 800;
		font-family: MicrosoftYaHei;
		line-height: 1.5;
		display: inline-block;
		font-size: 26rpx;
		color: rgba(0, 0, 0, 0.65);
	}
}
</style>
